var t = getApp(), a = {};

Page({
    data: {
        language: "",
        columns: [],
        showPopup2: !1,
        showPopup: !1,
        result: [],
        min_price: "",
        max_price: "",
        keyword: "",
        status: "",
        store: "",
        store_id: "",
        commodity_data: [],
        catetory_menus: [],
        parentid: [],
        childid: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        t.store && this.setData({
            store: t.store
        }), t.store_id && this.setData({
            store_id: t.store_id
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {
        this.initData(), this._getJson();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    chooseStatus: function(t) {
        this.setData({
            status: t.currentTarget.dataset.status
        });
    },
    onChange1: function(t) {
        var e = t.detail, o = e.picker, s = e.value;
        o.setColumnValues(1, a[s[0].value].list);
    },
    onConfirm: function(t) {
        this.setData({
            parentid: t.detail.value[0].value
        }), t.detail.value[1] ? this.setData({
            childid: t.detail.value[1].value
        }) : this.setData({
            childid: ""
        }), this.AddGoods();
    },
    onClose2: function() {
        this.setData({
            showPopup2: !1
        });
    },
    onSmallInput: function(t) {
        var a = t.detail.value;
        this.setData({
            min_price: a
        });
    },
    onInput: function(t) {
        var a = t.detail.value;
        this.setData({
            max_price: a
        });
    },
    onClose: function() {
        this.setData({
            showPopup: !1
        });
    },
    onChange: function(t) {
        this.setData({
            result: t.detail
        });
    },
    inpbtn: function(t) {
        var a = t.detail.value;
        this.setData({
            keyword: a
        });
    },
    inpbtnclear: function() {
        this.setData({
            keyword: ""
        });
    },
    toShowPopup2: function() {
        this.data.result.length <= 0 ? wx.showToast({
            icon: "none",
            title: "请选选择商品",
            duration: 1500
        }) : this.setData({
            showPopup2: !0
        });
    },
    classifyBolbtn: function() {
        this.setData({
            showPopup: !0
        });
    },
    search: function() {
        this.setData({
            showPopup: !1
        }), this._getJson();
    },
    AddGoods: function() {
        var a, e = this;
        a = {
            store_id: this.data.store_id,
            updateSelect: "updateSelect",
            goods_ids: this.data.result,
            category: {
                parentid: [ this.data.parentid ],
                childid: [ this.data.childid ]
            }
        };
        var o = t.getNetAddresss("plugin.store-product.api.product.index");
        wx.showToast({
            title: "导入中",
            icon: "loading",
            duration: 1e4
        }), t._postNetWork({
            url: o,
            showToastIn: !1,
            data: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (e.setData({
                    result: [],
                    showPopup2: !1
                }), wx.hideToast(), wx.showToast({
                    icon: "success",
                    title: "导入成功",
                    duration: 1500
                })) : (wx.hideToast(), wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {}
        });
    },
    _getJson: function() {
        var e = this, o = "", s = {};
        e.setData({
            page: 1
        }), "store" == this.data.store ? (o = "plugin.store-product.api.product.index", 
        s = {
            store_id: this.data.store_id,
            getGoodsInformation: "getGoodsInformation",
            page: 1,
            search: {
                keyword: this.data.keyword,
                status: this.data.status,
                min_price: this.data.min_price,
                max_price: this.data.max_price
            }
        }) : "supplier" == this.data.store && (o = "plugin.supplier.frontend.goods.get-goods-list", 
        s = {
            sid: this.data.store_id
        });
        var i = t.getNetAddresss(o);
        t._postNetWork({
            url: i,
            showToastIn: !1,
            data: s,
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    if (e.setData({
                        commodity_data: []
                    }), "store" == e.data.store) {
                        var s = o.data.getGoodsInformation.catetory_menus;
                        if (s.length > 0 && e.data.columns.length <= 0) {
                            var i;
                            o.data.getGoodsInformation.catetory_menus.map(function(t, e) {
                                var o = [];
                                t.children && (o = t.children.map(function(t, a) {
                                    return {
                                        name: t.name,
                                        value: t.id,
                                        parent_id: t.parent_id
                                    };
                                })), a[t.id] = {
                                    name: t.name,
                                    value: t.id,
                                    list: o
                                };
                            }), i = [ {
                                values: Object.keys(a).map(function(t) {
                                    return {
                                        name: a[t].name,
                                        value: a[t].value
                                    };
                                })
                            }, {
                                values: a[s[0].id].list,
                                defaultIndex: 0
                            } ], e.setData({
                                columns: i
                            });
                        }
                        e.setData({
                            catetory_menus: o.data.getGoodsInformation.catetory_menus,
                            total_page: o.data.getGoodsInformation.list.last_page,
                            commodity_data: o.data.getGoodsInformation.list.data
                        });
                    } else if ("supplier" == e.data.store) {
                        for (var n = 0; n < o.data.list.length; n++) o.data.list[n].edit_active = !1;
                        console.log(o.data, "数组的格式"), e.setData({
                            total_page: o.data.list.last_page,
                            commodity_data: o.data.list.data
                        });
                    }
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    getMoreData: function() {
        var a = this, e = "", o = {};
        "store" == a.data.store ? (e = t.getNetAddresss("plugin.store-product.api.product.index"), 
        o = {
            store_id: a.data.store_id,
            getGoodsInformation: "getGoodsInformation",
            search: {
                keyword: this.data.keyword,
                status: this.data.status,
                min_price: this.data.min_price,
                max_price: this.data.max_price
            }
        }) : "supplier" == a.data.store && (e = t.getNetAddresss("plugin.supplier.frontend.goods.get-goods-list"), 
        o = {
            sid: a.data.store_id
        }), a.setData({
            isLoadMore: !1
        }), this.data.page >= this.data.total_page || (a.setData({
            page: this.data.page + 1
        }), o.page = a.data.page, t._postNetWork({
            url: e,
            data: o,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    if ("store" == a.data.store) a.setData({
                        commodity_data: a.data.commodity_data.concat(e.data.getGoodsInformation.list.data)
                    }); else if ("supplier" == a.data.store) {
                        for (var o = 0; o < e.data.list.data.length; o++) e.data.list.data[o].edit_active = !1;
                        a.setData({
                            commodity_data: a.data.commodity_data.concat(e.data.list.data)
                        });
                    }
                    a.setData({
                        isLoadMore: !0
                    });
                } else a.setData({
                    page: a.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        }));
    },
    initData: function() {
        this.setData({
            commodity_data: [],
            isLoadMore: !0,
            page: 1,
            total_page: 0
        });
    }
});